package com.pengxun.manager.controller.system;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pengxun.manager.model.system.PermissionApi;
import com.pengxun.manager.service.system.PermissionApiService;
import com.pengxun.manager.vo.AssignPermissionApiVO;
import com.pengxun.manager.vo.PermissionApiVO;
import com.szeastroc.common.jdbc.page.Page;
import com.szeastroc.common.result.Result;
import com.szeastroc.common.result.ResultUtils;

@RestController
@RequestMapping("/permissionApi")
public class  PermissionApiController{

   @Resource
   private PermissionApiService permissionApiService;
   
   @RequestMapping("/insert")
   public Result insert(@RequestBody PermissionApi permissionApi){
       try{
    	   Date date = new Date();
    	   permissionApi.setCreateDate(date);
    	   permissionApi.setUpdateDate(date);
          permissionApiService.insert(permissionApi);
       } catch (Exception e) {
			return ResultUtils.renderError(e.getMessage());
	   }
	   return ResultUtils.render();
   };
   
   @RequestMapping("/assignPermissionApi")
   public Result assignPermissionApi(@RequestBody AssignPermissionApiVO assignPermissionApiVO){
       try{
          permissionApiService.assignPermissionApi(assignPermissionApiVO);
       } catch (Exception e) {
			return ResultUtils.renderError(e.getMessage());
	   }
	   return ResultUtils.render();
   };
   
   @RequestMapping("/update")
   public Result update(@RequestBody PermissionApi permissionApi){
        try{
          permissionApiService.update(permissionApi);
       } catch (Exception e) {
			return ResultUtils.renderError(e.getMessage());
	   }
	   return ResultUtils.render();
   };
   
   @RequestMapping("/delete")
   public Result delete(Integer id){
       try{
          permissionApiService.delete(id);
       } catch (Exception e) {
			return ResultUtils.renderError(e.getMessage());
	   }
	   return ResultUtils.render();
   };
   
   @RequestMapping("/findByPage")
   public Result findByPage(@RequestBody PermissionApiVO permissionApiVO) {
		Page page = permissionApiService.findByPage(permissionApiVO);
		return ResultUtils.render(page);
	};
	
   @RequestMapping("/findById")
   public Result findById(Integer id) {
		PermissionApi permissionApi = permissionApiService.findById(id);
		return ResultUtils.render(permissionApi);
	};
	
	@RequestMapping("/findByPermissionCode")
	public Result findByPermissionCode(String permissionCode) {
		List<PermissionApi> permissionApis =  permissionApiService.findByPermissionCode(permissionCode);
		return ResultUtils.render(permissionApis);
	};
}
